<?php

namespace IDock\Insurance\TPIC\Response;

use IDock\Http\Response;
use IDock\Insurance\TPIC\Response\AllTPICResponse;
use IDock\Printer\PolicyPaymentPrinter;
use IDock\Printer\ProposalRecallPrinter;
use IDock\Printer\ProposalStatusPrinter;

class OrderStatusQueryResponse extends AllTPICResponse
{

    public $printer = ProposalStatusPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody()['body'] ?? '';
        $riskList = $this->formatArray($body['risk'] ?? []);
        $biStatus = $ciStatus = '';
        $biTip = $ciTip = '';
        foreach ($riskList as $value){
            if($value['riskCode'] == 'BS'){
                $this->printer->biInquiryNo = $value['proposalNo'] ?? '';
                $biStatus = $value['underwriteind'] ?? '';
                $biTip = $value['iLogInfo'] ?? '';
            }
            if($value['riskCode'] == 'BZ'){
                $this->printer->ciInquiryNo = $value['proposalNo'] ?? '';
                $ciStatus = $value['underwriteind'] ?? '';
                $ciTip = $value['iLogInfo'] ?? '';
            }
        }
        $this->printer->statusCode = 'U3';
        if(!empty($biStatus) && !empty($ciStatus)){
            if(in_array($biStatus,[1,3,6]) && in_array($ciStatus,[1,3,6])){
                $this->printer->statusCode = 'U1';
            }
            if(in_array($biStatus,[2,4,7]) or in_array($ciStatus,[2,4,7])){
                $this->printer->statusCode = 'U4';
            }
        }else{
            $status = $ciStatus ?: $biStatus;
            if(in_array($status,[1,3,6])){
                $this->printer->statusCode = 'U1';
            }
            if(in_array($status,[2,4,7])){
                $this->printer->statusCode = 'U4';
            }
        }
        if(!empty($ciTip)){
            $this->printer->messageTip = '交强险提示：'.$ciTip."\r\n";
        }
        if(!empty($biTip)){
            $this->printer->messageTip .= '商业险提示：'.$biTip;
        }
        $this->printer->argc['orderNo'] = $body['fcOrderInfo']['fcPolicyNo'] ?? [];
        return $this;
    }

}
